<template>
  <div class="home">
    <h2>home页面</h2>
    <ul>
      <li
        v-for="i in 10"
        :key="i"
        @click="change(i)"
        :class="{
          active: i == flag && i % 2 == 0,
          active2: i == flag && i % 2 != 0,
        }"
      >
        {{ i }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      flag: -1,
    };
  },
  methods: {
    change(i) {
      //传下来的i代表了当前点击的是哪一个，需要保存下来
      this.flag = i;
    },
  },
};
</script>
<style lang="scss">
.home {
  .active {
    background: palegoldenrod;
  }
  .active2 {
    background: paleturquoise;
  }
}
</style>
